package com.ssl.rms.utils;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * 描述：根据数据库表生成代码<br/>
 * 注意config.properties文件中，配置targetProject的时候，有子项目时记得加下子项目名称，否则就直接写src/main/java
 *
 * @author ssl
 * @create 2018/02/05 16:29
 */
public class Generator {
    public static void main(String[] args){
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        try{
            String path = Generator.class.getClass().getResource("/generatorConfig.xml").getPath();
            File configFile = new File(path);
            ConfigurationParser configurationParser = new ConfigurationParser(warnings);
            Configuration configuration = configurationParser.parseConfiguration(configFile);
            DefaultShellCallback callback = new DefaultShellCallback(overwrite);
            MyBatisGenerator myBatisGenerator = new MyBatisGenerator(configuration, callback, warnings);
            myBatisGenerator.generate(null);
            System.out.println("is success!");
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
